package edu.gatech.asthma.activity;

import edu.gatech.asthma.R;
import edu.gatech.asthma.database.DBAdapter;
import edu.gatech.asthma.ui_support.HelpMenuHelper;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
 * Activity that allows user to enter a new emergency contact
 */
public class CreateContactActivity extends Activity {
	
	DBAdapter database;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_create_contact);
		
		database = new DBAdapter(this);
		database.open();
		
		getActionBar().setTitle("Create contact.");
		
		final EditText name = (EditText)findViewById(R.id.txtContactName);
		final EditText number = (EditText)findViewById(R.id.txtContactNumber);
		Button save = (Button)findViewById(R.id.btnSave);
		
		save.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				String contactName = name.getText().toString();
				String contactNumber = number.getText().toString();
				
				database.addEmergencyContact(contactName, contactNumber);
				Intent i = new Intent(CreateContactActivity.this, ShowContactsActivity.class);
				CreateContactActivity.this.startActivity(i);
				finish();
			}
		});
		
	}
	
	/**
	 * User clicked the help button on this screen
	 * @param v ImageView clicked
	 */
	public void helpButtonClicked(View v) {
		HelpMenuHelper.displayHelpMessage(this);
	}

}
